from django.db import models
from datetime import datetime,date


# Create your models here.

# vip后台管理员表
class Vip(models.Model):
    username = models.CharField(max_length=32)
    password = models.CharField(max_length=32)
    state = models.IntegerField(default=1)
    addtime = models.DateTimeField(default=datetime.now)

    def toDict(self):
        return {'username': self.username, 'password': self.password, 'state': self.state, 'addtime': self.addtime}

    class Meta:
        db_table = "vip"


# 轮播图表
class Banner(models.Model):
    bannertypeid = models.IntegerField()
    bannertype = models.CharField(max_length=32)
    pic = models.CharField(max_length=255)

    class Meta:
        db_table = "banner"


# 商品分类表
class Goodstype(models.Model):
    name = models.CharField(max_length=255)

    class Meta:
        db_table = "goodstype"


# 商品信息表
class Goods(models.Model):
    typeid = models.IntegerField()
    type_name = models.CharField(max_length=32)
    goods_name = models.CharField(max_length=255)
    content = models.TextField()
    price = models.IntegerField()
    pic_url = models.CharField(max_length=255)
    url = models.CharField(max_length=255)
    boughtnum = models.IntegerField()
    clicknum = models.IntegerField()
    state = models.IntegerField()
    addtime = models.DateTimeField(default=datetime.now)
    recommend = models.IntegerField(default=0)

    class Meta:
        db_table = "goods"


# 文章信息分类表
class Articletype(models.Model):
    name = models.CharField(max_length=32)

    class Meta:
        db_table = "articletype"


# 文章信息表
class Article(models.Model):
    name = models.CharField(max_length=255)
    content = models.TextField()
    type_name = models.CharField(max_length=32)
    typeid = models.IntegerField()
    pic_url = models.CharField(max_length=255)
    clicknum = models.IntegerField()
    addtime = models.DateTimeField(default=datetime.now)
    recommend = models.IntegerField(default=0)

    class Meta:
        db_table = "article"


# 用户表
class Users(models.Model):
    userid = models.IntegerField()
    openid = models.CharField(max_length=255)
    nickname = models.CharField(max_length=32)
    province = models.CharField(max_length=32)
    city = models.CharField(max_length=32)
    sex = models.IntegerField()
    addtime = models.DateTimeField(default=datetime.now)

    class Meta:
        db_table = "users"


# 用户购买记录表
class Users_goods(models.Model):
    userid = models.IntegerField()
    openid = models.CharField(max_length=255)
    goods_id = models.IntegerField()
    goods_name = models.CharField(max_length=255)
    goods_type = models.IntegerField()
    orderid = models.IntegerField()
    addtime = models.DateTimeField(default=datetime.now)
    total = models.IntegerField()
    linkman = models.CharField(max_length=32)
    address = models.CharField(max_length=255)
    code = models.CharField(max_length=6)
    phone = models.CharField(max_length=16)

    class Meta:
        db_table = "users_goods"


# 收藏表
class Favourite(models.Model):
    userid = models.IntegerField()
    openid = models.CharField(max_length=255)
    goods_name = models.CharField(max_length=255)
    goods_type = models.IntegerField()
    goods_id = models.IntegerField()
    toatl = models.IntegerField()
    addtime = models.DateTimeField(default=datetime.now)

    class Meta:
        db_table = "favourite"
